let user = {
    name : "张三",
    age : 20,
    printName: function(){
        console.log(this.name);
    },
    printAge(){
        console.log(this.age);
    },
};

user.printInfo = function(){
    console.log(this.name +":" + this.age);
    console.log('${this.name}:${this.age}');
}
user.printAge();
user.printName();
user.printInfo();

//user.method();会报错
user.method?.(); //不会报错 ,没有这方法, 就不执行


//构造函数
function Dog(name,age){
    this.name = name;
    this.age = age;
}
let dog = new Dog("hh" ,2);